<script>
    // 定义数据
    let Data = {
        username: 'hw',
        password: 456789
    }
    let socket = new WebSocket('ws://localhost:4000');
    socket.onopen = function () {
        socket.send(JSON.stringify(Data)); // 向服务器发送数据
    }
    socket.onmessage = function (e) {
        console.log(JSON.parse(e.data)); // 接收服务器返回的数据
    }
</script>